package org.vestbjergbyggecenter.Model;

import java.util.ArrayList;

public class Customer extends Person {

	public double monthlyBill;
	public Category category;
	public ArrayList<Order> customerOrders;
	
	//Constructor
	public Customer(int customerID, String customerName, long customerCPR, String customerAddress, long customerPostalCode, String customerCity, String customerPhone, Category customerCategory)
	{
		super(customerID, customerName, customerCPR, customerAddress, customerPostalCode, customerCity, customerPhone);
		this.category=customerCategory;
		customerOrders=new ArrayList<Order>();
	}
	
	//Method to set the customer id.
	public void setID(int newID)
	{
		super.setId(newID);
	}
	
	//Method to return customer id.
	public int getID()
	{
		return super.getId();
	}
	
	//Method to return the monthly bill.
	public double getMonthlyBill()
	{
		ArrayList<Order> monthOrders = getMonthOrders();
		for(Order order:monthOrders)
		{
			monthlyBill += order.getTotalPrice();			
		}
		return monthlyBill;
	}	
	
	//Method to set the category.
	public void setCategory(Category newcategory)
	{
		this.category=newcategory;
	}

	//Method to get the category.
	public Category getcategory()
	{
		return category;
	
	}
	
	public void addOrder(Order order)
	{
		customerOrders.add(order);		
	}
	
	public ArrayList<Order> getMonthOrders()
	{
		ArrayList<Order> monthOrders=new ArrayList<Order>();;
	    
		for(Order order: getCustomerOrders())
		{
			if(order.getMonth(order.getOrderingDate()) == order.getMonth(order.getCurrentDate()) &&
					order.getYear(order.getOrderingDate()) == order.getYear(order.getCurrentDate()))
		    {
		    	monthOrders.add(order);
		    }
		}
		return monthOrders;
	}
	
	public ArrayList<Order> getCustomerOrders() {
		ArrayList<Order> orders = new ArrayList<>();
		for(Order order: customerOrders)
		{
			if(order.getCustomer().getID()==super.getId())
			{
				orders.add(order);
			}
		}
		return orders;
	}

	/*
	 * Method that shows what are a customer's orders.
	 * ID based
	 */
	public void printCustomerOrders()
	{
		System.out.println("Customer " + super.getName() + " has these orders: ");
		for(Order order: getCustomerOrders())
		{			
			System.out.println();
			order.printShort();				
		}
	}
	
	public void printCustomerMonthBill()
	{
		System.out.println("Customer " + super.getName() + " bill: ");	
		for(Order order:getMonthOrders())
		{
			System.out.println();
			order.printShort();	
		}
		System.out.println("Total: " + getMonthlyBill());
	}
	
	public void printCustomer()
	{
		System.out.println("  " + getId() + " | " + getName() + " | " + getPhone() + " | " + getAddress() + " | " + getPostalCode() + " | "+ getCity() + " | " + getCPR() + "  |  ");		
	}
}
